From 76b87272a6fc48384405a17a55761b44f535cbe5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 12 Oct 2020 21:34:16 -0400 Subject: [PATCH] spinbutton: Implement GtkAccessible This copies what was done for GtkEntry: get the focused state from the GtkText within. We also add a private getter for the text widget, which was missing here. --- gtk/gtkspinbutton.c | 38 ++++++++++++++++++++++++++++++++++++++ gtk/gtkspinbuttonprivate.h | 27 +++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 gtk/gtkspinbuttonprivate.h diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index b0cbfcf852..b0ff1672f0 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -29,6 +29,9 @@ #include "gtkspinbutton.h" +#include "gtkspinbuttonprivate.h" + +#include "gtkaccessibleprivate.h" #include "gtkadjustment.h" #include "gtkbox.h" #include "gtkbutton.h" @@ -305,12 +308,15 @@ static void gtk_spin_button_default_output (GtkSpinButton *spin_button); static void gtk_spin_button_update_width_chars (GtkSpinButton *spin_button); +static void gtk_spin_button_accessible_init (GtkAccessibleInterface *iface); static guint spinbutton_signals[LAST_SIGNAL] = {0}; static GParamSpec *spinbutton_props[NUM_SPINBUTTON_PROPS] = {NULL, }; G_DEFINE_TYPE_WITH_CODE (GtkSpinButton, gtk_spin_button, GTK_TYPE_WIDGET, G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL) + G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE, + gtk_spin_button_accessible_init) G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_spin_button_editable_init) G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE, @@ -572,6 +578,31 @@ gtk_spin_button_editable_init (GtkEditableInterface *iface) iface->insert_text = gtk_spin_button_insert_text; } +static gboolean +gtk_spin_button_accessible_get_platform_state (GtkAccessible *self, + GtkAccessiblePlatformState state) +{ + GtkSpinButton *spin_button = GTK_SPIN_BUTTON (self); + + switch (state) + { + case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE: + return gtk_widget_get_focusable (spin_button->entry); + case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED: + return gtk_widget_has_focus (spin_button->entry); + default: + g_assert_not_reached (); + } +} + +static void +gtk_spin_button_accessible_init (GtkAccessibleInterface *iface) +{ + GtkAccessibleInterface *parent_iface = g_type_interface_peek_parent (iface); + iface->get_at_context = parent_iface->get_at_context; + iface->get_platform_state = gtk_spin_button_accessible_get_platform_state; +} + static void gtk_cell_editable_spin_button_activated (GtkText *text, GtkSpinButton *spin) { @@ -2310,3 +2341,10 @@ gtk_spin_button_update (GtkSpinButton *spin_button) else gtk_spin_button_set_value (spin_button, val); } + +GtkText * +gtk_spin_button_get_text_widget (GtkSpinButton *spin_button) +{ + return GTK_TEXT (spin_button->entry); +} + diff --git a/gtk/gtkspinbuttonprivate.h b/gtk/gtkspinbuttonprivate.h new file mode 100644 index 0000000000..2a83077faa --- /dev/null +++ b/gtk/gtkspinbuttonprivate.h @@ -0,0 +1,27 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include +#include + +G_BEGIN_DECLS + +GtkText *gtk_spin_button_get_text_widget (GtkSpinButton *spin_button); + +G_END_DECLS -- 2.30.2